from celery_tasks.main import celery_app
from . import constants
from celery_tasks.sms.yuntongxun.sms import CCP
import logging
logger = logging.getLogger('django')


# 使用装饰器将以下任务装饰为异步任务
@celery_app.task(name='send_sms_code')
def send_sms_code(mobile, sms_code):
    try:
        result = CCP().send_template_sms(mobile, {sms_code, constants.SMS_CODE_EXPIRES // 60}, 1)
        print('短信正在发送,返回%s' % result)
    except Exception as e:
        logger.error('发送短信异常','mobile:%s message:%s' % (mobile, e))
    else:
        if result == 0:
            logger.error('发送验证码成功')
        else:
            logger.error('发送验证码失败')
